
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"  %>

<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>订单详情</title>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1">
    <!-- <link rel="shortcut icon" href="/favicon.ico"> -->
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">

    <link rel="stylesheet" href="<%=basePath %>/resources/Public/Vendor/SUI/dist/css/sm.min.css">
    <link rel="stylesheet" href="<%=basePath %>/resources/Public/Vendor/SUI/dist/css/sm-extend.min.css">
    <link rel="stylesheet" type="text/css" href="<%=basePath %>/resources/Public/Vendor/icon/iconfont.css">

    <link rel="stylesheet" href="<%=basePath %>/resources/Public/css/common.css">
</head>
<body>
<div class="page-group">

    <div class="page xgj-orderDetal" id='xgj-orderDetal'>

        <div class="content " style="margin-bottom: 0.5rem">
            <div class="content-block order-status" >
                <div style="color: #66CC9A;text-align:center">
                    <span class="icon iconfont icon-zhifu" style="display: none;"></span>
                    <span class="icon iconfont icon-daijiedan" style="display: none"></span>
                    <span class="icon iconfont icon-yijiedan" style="display: none"></span>
                    <span class="icon iconfont icon-fuwuzhong" style="display: none"></span>
                    <span class="icon iconfont icon-wangongyishenhe" style="display: none"></span>
                    <span class="icon iconfont icon-shenhezhong" style="display: none"></span>
                    <span class="icon iconfont icon-tuikuanzhong" style="display: none"></span>
                    <span class="icon iconfont icon-yituikuan" style="display: none"></span>
                    <span class="icon iconfont icon-yiwancheng" style="display: none"></span>
                    <span id="state" class="tab-label" style="margin-top: -.75rem;">${state}</span>
                    <%--<span id="stateValue" class="tab-label" style="display: none">${stateValue}</span>--%>
                </div>
                <p class="tishiyu">
                </p>
            </div>
            <div class="list-block">
                <div class="card">
                    <div class="card-content">
                        <div class="list-block media-list">
                            <ul>
                                <li class="item-content">
                                    <div class="item-inner">
                                        <div class="item-title-row">
                                            <div class="item-title">业主：${uname}</div>
                                            <div class="pull-right">
                                                <span class="">${phone}</span>
                                            </div>
                                        </div>
                                        <%--<div class="item-subtitle" style="width:500px; height:auto; float:left;">服务地址: ${address}</div>--%>
                                        <div class="item-title-row">
                                            <div class="item-title label" style="float:left">服务地址:</div>
                                            <div class="item-input">
                                                <%--<textarea style="overflow-y:hidden;height: auto;" readonly="readonly">${address}</textarea>--%>
                                                <%--<input type="text" value="${address}">--%>
                                                <p style="margin-top: 12px;">${address}</p>
                                            </div>
                                        </div>
                                    </div>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
            <div class="list-block " style=" margin-bottom:50px ">
                <ul>
                    <li>
                        <div class="item-content ">
                            <div class="item-inner">
                                <div class="item-title label">订单编号:</div>
                                <div class="item-input">
                                    <input type="text" id="orderNo" value="${orderNo}" readonly="readonly">
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="item-content ">
                            <div class="item-inner">
                                <div class="item-title label">订单金额:</div>
                                <div class="item-input">
                                    <input type="text" id="price" value="${money}" readonly="readonly">
                                    <input type="hidden" id="money" value="${money}" readonly="readonly">
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="item-content ">
                            <div class="item-inner">
                                <div class="item-title label">下单时间:</div>
                                <div class="item-input">
                                    <input type="text" id="createTime" value="${createTime}" readonly="readonly">
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="item-content ">
                            <div class="item-inner">
                                <div class="item-title label">服务类型:</div>
                                <div class="item-input">
                                    <%--<input type="text" id="serviceType" value="${reserviceType}" readonly="readonly">--%>
                                    <p>${reserviceType}</p>
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="item-content ">
                            <div class="item-inner">
                                <div class="item-title label">服务时间:</div>
                                <div class="item-input">
                                    <input type="text" id="serviceTime" value="${reserviceTime}" readonly="readonly">
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="item-content item-worker">
                            <div class="item-title label">服务师傅:</div>
                            <c:if test="${hasWorker}">
                                <div class="item-media">
                                        <%--<img src="<%=basePath %>/resources/Public/images/demo/fffffffff.jpg"  class="avatar" style="width: 4rem;height: 4rem;" >--%>
                                    <img src="<%=basePath %>${craftsman.logoUrl}"  class="avatar" style="width: 4rem;height: 4rem;" >
                                </div>
                                <div class="item-inner">
                                    <div class="item-title-row">
                                        <div class="item-title item-order-workername">${craftsman.name}</div>
                                        <div class="item-subtitle item-order-star">
                                            <div id="starBg" class="star_bg">
                                                <input type="radio" id="starScore4" class="score score_1" checked="checked" value="5" name="score">
                                                <a href="#" class="star star_1" title="好"><label for="starScore4">较好</label></a>
                                            </div>
                                        </div>
                                        <div class="item-subtitle item-order-num">${craftsman.num}单</div>
                                    </div>
                                    <div class="item-after">
                                        <a href="sms:${craftsman.phone}" class="sms">
                                            <span class="icon iconfont icon-duanxin " style="font-size: 26px;"></span>
                                        </a>
                                        <a href="tel:${craftsman.phone}">
                                            <span class="icon iconfont icon-bohao " style="font-size: 26px;"></span>
                                        </a>
                                    </div>
                                </div>
                            </c:if>
                            <c:if test="${!hasWorker}">
                                <div class="item-inner">
                                    <div class="item-title-row">
                                        <div class="item-title item-order-workername">${craftsman.name}</div>
                                    </div>
                                </div>
                                <div class="item-after">
                                    <a href="tel:${craftsman.phone}">
                                        <span class="icon iconfont icon-bohao " style="font-size: 26px;"></span>
                                    </a>
                                </div>
                            </c:if>

                            <%--<div class="item-inner">
                                <div class="item-title-row">
                                    <div class="item-title item-order-workername">${craftsman.name}</div>
                                    <div class="item-subtitle item-order-star">
                                        <div id="starBg" class="star_bg">
                                            <input type="radio" id="starScore4" class="score score_4" checked="checked" value="5" name="score">
                                            <a href="#" class="star star_4" title="好"><label for="starScore4">较好</label></a>
                                        </div>
                                    </div>
                                    <div class="item-subtitle item-order-num">${craftsman.num}单</div>
                                </div>
                                <div class="item-after">
                                    <a href="sms:${craftsman.phone}" class="sms">
                                        <span class="icon iconfont icon-duanxin "></span>
                                    </a>
                                    <a href="tel:${craftsman.phone}">
                                        <span class="icon iconfont icon-bohao "></span>
                                    </a>
                                </div>
                            </div>--%>
                        </div>
                    </li>
                    <li>
                        <div class="item-content ">
                            <div class="item-inner">
                                <div class="item-title label">业主留言:</div>
                                <div class="item-input">
                                    <%--<textarea style="overflow-y:hidden;overflow:visible" readonly="readonly">${message}</textarea>--%><!--style="overflow-y:hidden;"-->
                                    <p style="margin-top: 2px;padding-bottom: 2px;">${message}</p>
                                </div>
                            </div>
                        </div>
                    </li>
                </ul>
            </div>

        </div>
        <nav class="bar bar-tab disable-router" style="padding-top: 0;"><!--bar bar-tab row no-gutter-->
            <div class="col-30 item-inner-left" style="padding-top: 0;">
                &nbsp;&nbsp;
            </div>
            <div class="col-70 item-inner-right pull-right content-block" style="float: right;position: fixed;bottom: 0;width: 100%;margin-top: 0;margin-bottom: 1px;">
                <p class=" pull-right">
                    <a href="javascript:cancel()" id="cancel" class="button active button-fill external" style="display: none">取消订单</a>
                    <a href="javascript:pay()" id="pay" class="button button-fill external" style="display: none;border:1px solid #E77D00;color: #E77D00;">付款</a>
                    <a href="javascript:confirmOrder()" id="confirm" class="button button-fill external" style="display: none">确认完成</a>
                    <a href="javascript:deleteOrder()" id="delete" class="button button-fill external" style="display: none">删除订单</a>
                    <a href="<%=path%>/wx/order/assessPage.do?orderNo=${orderNo}" id="assess" class="button button-fill external" style="display: none">评价</a>
                    <a href="javascript:void(0)" id="cusService" style="display: inline" class="button button-fill external">联系客服</a>
                </p>
            </div>
        </nav>
    </div>
</div>
<!--   此处引入 tabar.php -->
<!-- / 此处引入 tabar.php -->

<script type="text/javascript" src='<%=basePath %>resources/Public/Vendor/SUI/dist/js/zepto.js'></script>
<script type="text/javascript">
    $.config = {
        // 路由功能开关过滤器，返回 false 表示当前点击链接不使用路由-
        routerFilter: function($link) {
            // 某个区域的 a 链接不想使用路由功能
            if ($link.is('.disable-router a')) {
                return false;
            }
            return true;
        }
    };
</script>
<script src='<%=basePath %>/resources/Public/Vendor/SUI/dist/js/sm.js'></script>
<script src="<%=basePath %>/resources/Public/Vendor/SUI/dist/js/sm-city-picker.min.js" ></script>
<script src='<%=basePath %>/resources/Public/Vendor/SUI/dist/js/sm-extend.min.js'></script>
<script src='<%=basePath %>/resources/Public/js/common.js'></script>


<script type="text/javascript">
    $.init();
    $(function () {
        init_page();
    });

    function init_page() {
        var state = ${stateValue};
        var canCancel = ${canCancel};
        var assess = ${hasAssess};
        if (state == 1) {
            $(".icon-zhifu").show();
            $(".tishiyu").text("付款后，师傅很快就会联系您哦");
            $("#cancel").show();
            $("#pay").show();
            /*$("#confirm").style.display = "none";
             $("#delete").style.display = "none";
             $("#assess").style.display = "none";*/
        } else if (state == 2){
            $(".icon-daijiedan").show();
            $(".tishiyu").text("不要着急，师傅很快就会联系您哦");
            $("#cancel").show();
            /*$("#pay").style.display = "show";*/
            /*$("#confirm").style.display = "none";
             $("#delete").style.display = "none";
             $("#assess").style.display = "none";*/
        } else if (state == 3) {
            $(".icon-yijiedan").show();
            $(".tishiyu").text("若取消订单，请至少在师傅上门前两小时联系客服");
            if (canCancel == true) {
                $("#cancel").show();
            }
            $("#confirm").show();
        } else if (state == 4) {
            $(".icon-fuwuzhong").show();
        } else if (state == 5) {
            $(".icon-wangongyishenhe").show();
            $("#confirm").show();
        } else if (state == 6) {
            $(".icon-yiwancheng").show();
            $("#delete").show();
            if (!assess) {
                $("#assess").show();
            }
        } else if (state == 7) {
            $(".icon-shenhezhong").show();
        } else if (state == 8) {
            $(".icon-tuikuanzhong").show();
        } else if (state == 9) {
            $(".icon-yituikuan").show();
            $("#delete").show();
        }
    }

    function cancel() {
        //alert($("#phone").val());
        /*var state = $("#stateValue").val();
         var orderNo = $("#orderNo").val();*/
        var state = ${stateValue};
        var orderNo = '${orderNo}';
        if (state == 1) {
            $.confirm("确认取消订单？", "温馨提示",
                function () {
                    $.ajax({
                        type: "post",
                        url: "<%=path%>/wx/order/cancelOrderForUnpay.do",
                        data: "orderNo=" + orderNo,
                        success : function(data){
                            if (data.code == 200) {
                                var openId = data.data;
                                window.location.href = "<%=path%>/wx/order/qOrders.do?openId=" + openId;
                            } else {
                                $.toast("订单取消失败")
                            }
                        },
                        error: function(){
                            $.toast("订单取消失败")
                        }
                    });
                }
            );
        } else {
            $.confirm("确定取消订单并申请退款么？","温馨提示",
                function () {
                    $.ajax({
                        url: "<%=path%>/wx/order/cancelOrder.do",
                        method: 'POST',
                        dataType: 'json',
                        data: "orderNo=" + orderNo,
                        success: function (data) {
                            if (data.Code == "0000") {
                                $("#state").html(data.state);
                                $(".icon.iconfont.icon-daijiedan").hide();
                                $(".icon.iconfont.icon-yijiedan").hide();
                                $(".icon.iconfont.icon-shenhezhong").show();
                                $(".tishiyu").hide();
                                $("#cancel").hide();
                                $.toast(data.Message);
                            } else if (data.Code == "0001") {
                                $.confirm(data.Message, "温馨提示",
                                    function () {
                                        $.ajax({
                                            url: "<%=path%>/wx/order/cancelOrder.do",
                                            method: 'POST',
                                            dataType: 'json',
                                            data: "orderNo=" + orderNo,
                                            success: function (data) {
                                                if (data.code == 200) {
                                                    $("#state").html(data.data);
                                                    $(".icon.iconfont.icon-daijiedan").hide();
                                                    $(".icon.iconfont.icon-yijiedan").hide();
                                                    $(".icon.iconfont.icon-shenhezhong").show();
                                                    $(".tishiyu").hide();
                                                    $("#cancel").hide();
                                                    $.toast(data.hint);
                                                } else {
                                                    $.toast(data.hint);
                                                }
                                            },
                                            error:function () {
                                                
                                            }
                                        })
                                    }
                                )
                            } else {
                                $.toast(data.Message);
                            }
                        },
                        error:function () {
                            $.toast(data.Message);
                        }
                    });
                }
            )
        }

        /*if (state == 1) {
         $.ajax({
         type: "post",
         url: "<=path%>/wx/order/cancelOrderForUnpay.do",
         data: "orderNo=" + orderNo,
         success : function(){
         },
         error: function(){
         }
         });
         } else {
         $.ajax({
         url: "<=path%>/wx/order/cancelOrder.do",
         method: 'POST',
         dataType: 'json',
         data: "orderNo=" + orderNo,
         success: function (data) {
         if (data.Code == "0000") {
         //window.location.href = '<=basePath %>wx/order/.do';
         $("#state").html(data.state);
         //$("#stateValue").html(data.stateValue);
         $(".icon-daijiedan").style.display = "none";
         $(".icon-yijiedan").style.display = "none";
         $(".icon-shenhezhong").show();
         $(".tishiyu").text("");
         $("#cancel").style.display='none';
         $.toast(data.Message);
         } else {
         $.toast(data.Message);
         }
         }
         });
         }*/

    }

    //确认订单
    function confirmOrder() {
        var orderNo = $("#orderNo").val();
        $.confirm("确认订单已完成？", "温馨提示",
            function () {
                $.ajax({
                    type: "post",
                    url: "<%=path%>/wx/order/confirmOrder.do",
                    data: "orderNo=" + orderNo,
                    success : function(data){
                        if (data.code == 200) {
                            var orderNo = data.data;
                            window.location.href = "<%=path%>/wx/order/assessPage.do?orderNo=" + orderNo;
                        } else {
                            $.toast("订单确认失败！");
                        }
                    },
                    error: function(){
                        $.toast("订单确认失败！");
                    }
                });
            }
        );
    }

    function  deleteOrder() {
        var orderNo = $("#orderNo").val();
        $.confirm("确认删除该订单？", "温馨提示",
            function () {
                $.ajax({
                    type: "post",
                    url: "<%=path%>/wx/order/delOrder.do",
                    data: "orderNo=" + orderNo,
                    success : function(data){
                        if (data.code == 200) {
                            var openId = data.data;
                            window.location.href = "<%=path%>/wx/order/qOrders.do?openId=" + openId;
                        } else {
                            $.toast("订单删除失败！");
                        }
                    },
                    error: function(){
                        $.toast("订单删除失败！");
                    }
                });
            }
        );
    }

    function pay(){
        var money= $("#money").val();
        var orderNo = $("#orderNo").val();
        $.ajax({
            type: "POST",
            url: "<%=path%>/wx/business/depositweixin.do",
            data: {
                "money": money,
                "trade_no":orderNo
            },
            dataType: "json",
            success: function (data) {
                if (data.result == "0000") {
                    WeixinJSBridge.invoke(
                        'getBrandWCPayRequest', {
                            "appId": data.appId,     //公众号名称，由商户传入
                            "timeStamp": data.timeStamp,         //时间戳，自1970年以来的秒数
                            "nonceStr": data.nonceStr, //随机串
                            "package": data.packageValue,
                            "signType": "MD5",         //微信签名方式:
                            "paySign": data.paySign    //微信签名
                        },
                        function (res) {
                            if (res.err_msg == "get_brand_wcpay_request:ok") {
                                location.href = "<%=path%>/wx/order/qOrders.do"
                            }
                            isSignature = false;
                        }
                    );

                } else {
                    $.toast("参数配置有误");
                    isSignature = false;
                }
            }
        });
    }
</script>

</body>
</html>
